extends Node2D

# 
func _ready():
	# add_gui();
	add_container()


func add_sample():
	var SampleEntity = load("MoveEntity.gd");
	var temp = SampleEntity.new();
	self.add_child(temp);

func add_knight():
	var knight = load("res://KnightSprite.gd")
	var temp = knight.new();
	self.add_child(temp);

	var knigh2 = load("res://Knight2.gd")
	temp = knigh2.new();
	self.add_child(temp)

func area2kobj():
	# add_adrea2d(true);
	add_kobj()

	var obj2 = add_adrea2d(false);
	obj2.x = 400;
	obj2.position = Vector2(obj2.x,obj2.y);

func add_adrea2d(isMove:bool):
	var AreaObj = load("res://AreaObj.gd");
	var temp = AreaObj.new();
	temp.isMove = isMove;
	self.add_child(temp)
	return temp;

func add_kobj():
	var KObj = load("res://KObj.gd");
	var temp = KObj.new();
	self.add_child(temp);
	return temp;


func add_static():
	# 静态体
	var StaticObj = load("res://StaticObj.gd");

	var temp:StaticObj = StaticObj.new(300,300);
	self.add_child(temp);

	var KDemo = load("res://KDemo.gd");
	var temp1 = KDemo.new();
	self.add_child(temp1);

	var RDemo = load("res://RDemo.gd")
	var temp2 = RDemo.new();
	self.add_child(temp2);

func add_container():
	var layer = CanvasLayer.new();
	# var con = hbox()
	# var con = vbox()
	# var con = cbox()
	# var con = hscrollbox()
	# var con = vscrollbox()
	var con = gbox();
	
	layer.add_child(con)

	self.add_child(layer)
	pass

func hbox():
	# 水平排列
	var hbox = HBoxContainer.new();
	for i in 5 :
		var color_btn = ColorPickerButton.new();
		color_btn.text = "ColorPick";
		hbox.add_child(color_btn)

	return hbox



func vbox():
	# 垂直排列
	var vbox = VBoxContainer.new();
	for i in 5 :
		var color_btn = ColorPickerButton.new();
		color_btn.text = "ColorPick";
		vbox.add_child(color_btn)

	return vbox
	

func cbox():
	# 5个重复都在中间
	var cbox = CenterContainer.new();
	# 必须设置大小
	cbox.rect_size = Vector2(200,200)

	for i in 5 :
		var color_btn = ColorPickerButton.new();
		color_btn.text = "ColorPick";
		cbox.add_child(color_btn)

	return cbox

func hscrollbox():
	var hs = ScrollContainer.new();
	# 必须设置大小
	hs.rect_size = Vector2(50,50)
	hs.scroll_horizontal_enabled = true
	hs.add_child(hbox())
	return hs

func vscrollbox():
	var vs = ScrollContainer.new();
	# 必须设置大小
	vs.rect_size = Vector2(150,50)
	vs.scroll_vertical_enabled = true
	vs.add_child(vbox())
	return vs

func gbox():
	var gbox = GridContainer.new()
	gbox.columns = 4;

	for i in 15 :
		var color_btn = ColorPickerButton.new();
		color_btn.text = "ColorPick";
		gbox.add_child(color_btn)

	return gbox

func add_gui():
	# var LabelObj = load("res://LabelDemo.gd");
	# var l = LabelObj.new();
	# self.add_child(l);

	# rich不行
	# var RichLabelDemo = load("res://RichLabelDemo.gd")
	# var temp  = RichLabelDemo.new();
	# self.add_child(temp)

	# var InputDemo = load("res://InputDemo.gd");
	# var i = InputDemo.new();
	# self.add_child(i);


	# var TextAreaDemo = load("res://TextAreaDemo.gd");
	# var i = TextAreaDemo.new();
	# self.add_child(i);

	# var ButtonDemo = load("res://ButtonDemo.gd");
	# var i = ButtonDemo.new();
	# self.add_child(i);

	# var CheckDemo = load("res://CheckDemo.gd");
	# var s = ["苹果","西瓜",'香蕉'];
	# var x = 0;
	# for t in s:
	# 	print(t);
	# 	var i = CheckDemo.new(t);
	# 	i.margin_left = x;
	# 	x = x + 200;

	# 	self.add_child(i);


	# var CheckBtn = load("res://CheckBtn.gd");
	# var s = ["苹果","西瓜",'香蕉'];
	# var x = 0;
	# for t in s:
	# 	var i = CheckBtn.new(t);
	# 	i.margin_left = x;
	# 	x = x + 200;

	# 	self.add_child(i);

	# var color_btn = ColorPickerButton.new();
	# color_btn.text = "ColorPick";
	# self.add_child(color_btn)

	# var mbtn = MenuButton.new();
	# mbtn.text = "MenuBtn";
	# mbtn.get_popup().add_item("item1");
	# mbtn.get_popup().add_item("item2");
	# mbtn.get_popup().add_item("item3");
	# self.add_child(mbtn)

	# var obtn = OptionButton.new();
	# obtn.text="OptionBtn";
	# obtn.add_item("item1")
	# obtn.add_item("item2")
	# obtn.add_item("item3")
	# self.add_child(obtn)

	# var tbtn = ToolButton.new();
	# tbtn.text="ToolBtn";
	# self.add_child(tbtn)

	# var lbtn = LinkButton.new();
	# lbtn.text="https://www.baidu.com";
	# self.add_child(lbtn)

	# var tbtn = TextureButton.new();
	# tbtn.texture_normal = load("res://icon.png")
	# self.add_child(tbtn)
	# tbtn.connect("pressed",self,"_btn_press");

	# var rect = ColorRect.new();
	# rect.color = Color(1,0,0,1);
	# # 需要设置大小
	# rect.rect_size = Vector2(100,100);
	# self.add_child(rect)

	# var border_rect = ReferenceRect.new();
	# # 需要设置大小
	# border_rect.rect_size = Vector2(100,100);
	# border_rect.border_color = Color(1,0,0,1);
	# border_rect.border_width = 3;
	# # 需要设置模式
	# border_rect.editor_only = false
	# self.add_child(border_rect)

	# var trect = TextureRect.new();
	# trect.flip_v = true;
	# trect.texture = load("res://icon.png");
	# self.add_child(trect)

	# var nrect = NinePatchRect.new();
	# # 需要设置大小 拉伸图像
	# nrect.rect_size = Vector2(150,100)
	# nrect.texture = load("res://icon.png");
	# self.add_child(nrect)
	# var pro = ProgressBar.new();
	# # 需要设置大小
	# pro.rect_size = Vector2(100,30);
	# pro.value = 50
	# self.add_child(pro)

	# var scroll = HScrollBar.new();
	# # 需要设置大小
	# scroll.rect_size = Vector2(100,30);
	# scroll.value = 50
	# self.add_child(scroll)

	# var scroll = VScrollBar.new();
	# # 需要设置大小
	# scroll.rect_size = Vector2(30,100);
	# scroll.value = 50
	# self.add_child(scroll)

	# var slide = HSlider.new();
	# # 需要设置大小
	# slide.rect_size = Vector2(100,30);
	# slide.value = 50
	# self.add_child(slide)

	# var slide = VSlider.new();
	# # 需要设置大小
	# slide.rect_size = Vector2(30,100);
	# slide.value = 50
	# self.add_child(slide)

	# var spin_box = SpinBox.new()
	# self.add_child(spin_box)
	# var line_edit = spin_box.get_line_edit()
	# line_edit.context_menu_enabled = false
	# spin_box.align = LineEdit.ALIGN_RIGHT

	# var sep = HSeparator.new();
	# # 需要设置大小
	# sep.rect_size = Vector2(100,30);
	# self.add_child(sep)

	# var sep = VSeparator.new();
	# # 需要设置大小
	# sep.rect_size = Vector2(30,100);
	# self.add_child(sep)

	pass

func _btn_press():
	# Popup,PopupDialog,PopupPanel无效 
	# 是作为容器使用

	# var d = AcceptDialog.new();
	# self.add_child(d)
	# d.popup_centered()

	# var d = ConfirmationDialog.new();
	# self.add_child(d)
	# d.popup_centered()

	# var d = PopupDialog.new();
	# var d = Popup.new();
	# var d = PopupPanel.new();

	# var lbtn = LinkButton.new();
	# lbtn.text="https://www.baidu.com";
	# d.add_child(lbtn)

	# self.add_child(d)
	# d.popup_centered()

	var d = FileDialog.new();
	self.add_child(d)
	d.popup_centered()

	# EditorFileDialog,ScriptCreateDialog
	# 编辑器中使用
	# var d = EditorFileDialog.new();
	# self.add_child(d)
	# d.popup_centered()
